package j2se.动态代理实现;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Created by jingqing.zhou on 2015/5/7.
 */
public class ProxyMain {
    public static void main(String[] args) {
        //代理的目标对象
        ProxyInterface targetObject = new TargetObject();
        //代理对象
        ProxyObject proxyObject = new ProxyObject();
        proxyObject.setTargetObject(targetObject);

        //转换成InvocationHandler
        InvocationHandler handler = proxyObject;

        Object proxy = Proxy.newProxyInstance(targetObject.getClass().getClassLoader(),targetObject.getClass().getInterfaces(),handler);
        ((ProxyInterface)proxy).proxyMethod();

    }
}
